package com.java.base.javabase.datademo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName DateDemo
 * @Author FangShanShan
 * @Description 日期测试
 * @Date 2020/4/28 11:38
 */
public class DateDemo {

    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");

    public static void main(String[] args) throws ParseException {
        Calendar now = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。

        checkReconData("2020-05-05", now, " 10:10:00");
    }


    private static void checkReconData(String reconDate, Calendar now, String time) throws ParseException {
        Calendar nowTime = now;
        String nowDateShortStr = sdf1.format(now.getTime()); // 当前日期 yyyy-MM-dd 格式

        Date flagTime = sdf.parse(nowDateShortStr + time);
        Calendar flagTimeCalendar = Calendar.getInstance();
        flagTimeCalendar.setTime(flagTime);

        if (nowDateShortStr.equals(reconDate)) {
            // 要对账的日期是今天，不可对账
            System.out.println("对账只能对前一天的，当天不可对账");
            return;
        }

        now.add(Calendar.DAY_OF_WEEK, -1);
        String beforeNowDateShortStr = sdf1.format(now.getTime());
        System.out.println("昨天日期" + beforeNowDateShortStr);

        if (beforeNowDateShortStr.equals(reconDate)) {
            // 对账日期是当前日期的前一天， 当前时间要在标记时间之后
            if (nowTime.after(flagTimeCalendar)) {
                System.out.println("对账日期是当前日期的前一天， 当前时间要在标记时间之后" + nowDateShortStr + time);
                return;
            }

        }


    }

}